package com.shuqi.activity.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shuqi.activity.MyBookBagActivity.MyBook;
import com.shuqi.controller.R;

/**
 * 书包列表适配器
 */
public class MyBookBagAdapter extends BaseAdapter {

    private List<MyBook> books;
    private LayoutInflater inflater;

    // 构造
    public MyBookBagAdapter(Context context, List<MyBook> books) {
        this.inflater = LayoutInflater.from(context);
        this.books = books;
    }

    @Override
    public int getCount() {
        return books==null?0:books.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = null;
        Holder holder = null;
        if (convertView != null) {
            view = convertView;
            holder = (Holder) view.getTag();
        } else {
            view = inflater.inflate(R.layout.item_mybookbag, parent, false);
            holder = (Holder) view.getTag();
            if (holder == null) {
                holder = new Holder();
                holder.text_bookname = (TextView) view.findViewById(R.id.mybookbag_bookname);
                holder.text_des = (TextView) view.findViewById(R.id.mybookbag_des);
                view.setTag(holder);
            }
        }
        MyBook book = books.get(position);
        holder.text_bookname.setText(book.getBookName());
        holder.text_des.setText(book.getNumBag()+"个书包,"+book.getNumChapter()+"章");
        return view;
    }

    private static class Holder {
        public TextView text_bookname;// 书名
        public TextView text_des;// 书籍简介
    }

}
